{/* 这个为了方便查看，一个load只引入一个文件，实际可合并到一个load上 */}

{if condition="isset($useCkeditor)"}
{/* ckeditor */}
{load href="/static/js/ckeditor/ckeditor.js"}
{/if}

{if condition="isset($useColorpicker)"}
{/* colorpicker */}
{load href="/static/js/bootstrap-colorpicker/bootstrap-colorpicker.min.js" /}
{load href="/static/js/bootstrap-colorpicker/bootstrap-colorpicker.min.css" /}
{/if}

{if condition="isset($useDatepicker)"}
{/* datepicker */}
{load href="/static/js/bootstrap-datepicker/bootstrap-datepicker.min.js" /}
{load href="/static/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" /}
{load href="/static/js/bootstrap-datepicker/bootstrap-datepicker3.min.css" /}
{/if}

{if condition="isset($useMomentjs)"}
{/* moment.js */}
{load href="/static/js/momentjs/moment.min.js" /}
{load href="/static/js/momentjs/locale/zh-cn.min.js" /}
{/if}

{if condition="isset($useDatetimepicker)"}
{/* datetimepicker */}
{load href="/static/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js" /}
{load href="/static/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css" /}
{/if}

{if condition="isset($useEditormd)"}
{/* editormd */}
{load href="/static/js/editormd/css/editormd.css" /}
{load href="/static/js/editormd/editormd.js" /}
{/if}

{if condition="isset($useMagnificPopup)"}
{/* magnific-popup */}
{load href="/static/js/magnific-popup/magnific-popup.min.css" /}
{load href="/static/js/magnific-popup/magnific-popup.min.js" /}
{/if}

{if condition="isset($useWebuploader)"}
{/* webuploader */}
{load href="/static/js/webuploader/webuploader.css" /}
{load href="/static/js/webuploader/webuploader.js" /}
{/if}

{if condition="isset($useJcrop)"}
{/* Jcrop */}
{load href="/static/js/jcrop/css/Jcrop.min.css" /}
{load href="/static/js/jcrop/js/Jcrop.min.js" /}
{/if}

{if condition="isset($useTagsinput)"}
{/* tagsinput */}
{load href="/static/js/jquery-tagsinput/jquery.tagsinput.min.css" /}
{load href="/static/js/jquery-tagsinput/jquery.tagsinput.min.js" /}
{/if}

{if condition="isset($useClockpicker)"}
{/* clockpicker */}
{load href="/static/js/bootstrap-clockpicker/bootstrap-clockpicker.min.js" /}
{load href="/static/js/bootstrap-clockpicker/bootstrap-clockpicker.min.css" /}
{/if}

{if condition="isset($useUeditor)"}
{/* ueditor */}
{load href="/static/js/ueditor/themes/default/css/ueditor.css" /}
{load href="/static/js/ueditor/ueditor.config.js" /}
{load href="/static/js/ueditor/ueditor.all.min.js" /}
{/if}

{if condition="isset($useWangEditor)"}
{/* wangEditor */}
{load href="/static/js/wangEditor/wangEditor.js" /}
{/if}

{if condition="isset($fonticonpicker)"}
{/* fontIconPicker */}
{load href="/static/js/fontIconPicker/css/jquery.fonticonpicker.min.css" /}
{load href="/static/js/fontIconPicker/themes/bootstrap-theme/jquery.fonticonpicker.bootstrap.min.css" /}
{load href="/static/js/fontIconPicker/jquery.fonticonpicker.min.js" /}
{/if}

<script type="text/javascript">
$(document).ready(function(){
    {if condition="isset($useCkeditor)"}
    // ckeditor
    jQuery('.js-ckeditor').each(function () {
        var editor_id = $(this).attr('id');
        var editor    = CKEDITOR.replace(editor_id, {
            filebrowserImageUploadUrl: '/admin/attachment/upload/dir/images/from/ckeditor.html',
            image_previewText: ' ',
            height: $(this).data('height') || 400,
            width: $(this).data('width') || '100%',
            toolbarCanCollapse: true
        });
        editor.on('change', function( evt ) {
            editor.updateElement();
        });
    });
    {/if}
    
    {if condition="isset($useEditormd)"}
    var editormds   = {};
    // editormd编辑器
    $('.js-editormd').each(function () {
        var editormd_name = $(this).attr('name');
        var image_formats = $(this).data('image-formats') || [];
        var watch         = $(this).data('watch');

        editormds[editormd_name] = editormd(editormd_name, {
            height: 500, // 高度
            placeholder: '本编辑器支持Markdown编辑，左边编写，右边预览',
            watch : watch,
            searchReplace : true,
            toolbarAutoFixed: false, // 取消工具栏固定
            path : '/static/js/editormd/lib/', // 用于自动加载其他模块
            codeFold: true, // 开启代码折叠
            dialogLockScreen : false, // 设置弹出层对话框不锁屏
            imageUpload : true, // 开启图片上传
            imageFormats : image_formats, // 允许上传的图片后缀
            imageUploadURL : '/admin/attachment/upload/dir/images/from/editormd',
            toolbarIcons : function() {
                return [
                    "undo", "redo", "|",
                    "bold", "del", "italic", "quote", "|",
                    "h1", "h2", "h3", "h4", "h5", "h6", "|",
                    "list-ul", "list-ol", "hr", "|",
                    "link", "reference-link", "image", "code", "preformatted-text", "code-block", "datetime", "html-entities", "pagebreak", "|",
                    "goto-line", "watch", "preview", "fullscreen", "clear", "search", "|",
                    "help", "info"
                ]
            }
        });
    });
    {/if}

    {if condition="isset($useWebuploaderFiles)"}
    // 文件上传
    $('.js-upload-file,.js-upload-files').each(function () {
        var $input_file       = $(this).find('input');
        var $input_file_name  = $input_file.attr('name');
        // 是否多文件上传
        var $multiple         = $input_file.data('multiple');
        // 允许上传的后缀
        var $ext              = $input_file.data('ext');
        // 文件限制大小
        var $size             = $input_file.data('size');
        // 文件列表
        var $file_list        = $('#file_list_' + $input_file_name);

        // 实例化上传
        var uploader = WebUploader.create({
            // 选完文件后，是否自动上传。
            auto: true,
            // 去重
            duplicate: true,
            // swf文件路径
            swf: '/static/js/webuploader/Uploader.swf',
            // 文件接收服务端。
            server: '/admin/attachment/upload/dir/file',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id: '#picker_' + $input_file_name,
                multiple: $multiple
            },
            // 文件限制大小
            fileSingleSizeLimit: $size,
            // 只允许选择文件文件。
            accept: {
                title: 'Files',
                extensions: $ext
            }
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = '<li id="' + file.id + '" class="list-group-item file-item">' +
                '<i class="mdi mdi-close-circle-outline remove-file text-danger"></i> ' +
                file.name +
                '<div class="progress progress-sm remove-margin active"><div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div></div>'+
                '</li>';

            if ($multiple) {
                $file_list.append($li);
            } else {
                $file_list.html($li);
                // 清空原来的数据
                $input_file.val('');
            }
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $percent = $( '#'+file.id ).find('.progress-bar');
            $percent.css( 'width', percentage * 100 + '%' );
        });

        // 文件上传成功
        uploader.on( 'uploadSuccess', function( file, response ) {
            var $li = $( '#'+file.id );
            if (response.status == 1) {
                if ($multiple) {
                    if ($input_file.val()) {
                        $input_file.val($input_file.val() + ',' + response.id);
                    } else {
                        $input_file.val(response.id);
                    }
                    $li.find('.remove-file').attr('data-id', response.id);
                } else {
                    $input_file.val(response.id);
                }
            }
            // 加入提示信息
            $('<span class="text-'+ response.class +' float-right">'+ response.info +'</span>').prependTo( $li );
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id );
            $('<span class="text-danger float-right">上传失败</span>').prependTo( $li );
        });

        // 文件验证不通过
        uploader.on('error', function (type) {
            switch (type) {
                case 'Q_TYPE_DENIED':
                    showNotify('文件类型不正确，只允许上传后缀名为：'+$ext+'，请重新上传！', 'danger');
                    break;
                case 'F_EXCEED_SIZE':
                    showNotify('文件不得超过'+ ($size/1024) +'kb，请重新上传！', 'danger');
                    break;
            }
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            setTimeout(function(){
                $('#'+file.id).find('.progress').remove();
            }, 500);
        });

        // 删除文件
        $file_list.delegate('.remove-file', 'click', function(){
            if ($multiple) {
                var id  = $(this).data('id'),
                    ids = $input_file.val().split(',');

                if (id) {
                    for (var i = 0; i < ids.length; i++) {
                        if (ids[i] == id) {
                            ids.splice(i, 1);
                            break;
                        }
                    }
                    $input_file.val(ids.join(','));
                }
            } else {
                $input_file.val('');
            }
            $(this).closest('.file-item').remove();
        });
    });
    {/if}

    {if condition="isset($useWebuploaderImages)"}
    // 图片上传
    $('.js-upload-image,.js-upload-images').each(function() {
        var $input_file      = $(this).find('input'),
            $input_file_name = $input_file.attr('name'),
            $multiple        = $input_file.data('multiple'),  // 是否选择多个文件
            $ext             = $input_file.data('ext'),       // 支持的文件后缀，示例以图片为例
            $size            = $input_file.data('size');      // 支持最大的文件大小

        var $file_list = $('#file_list_' + $input_file_name);
        var ratio = window.devicePixelRatio || 1;
        var thumbnailWidth = 165 * ratio;
        var thumbnailHeight = 110 * ratio;
        
        var uploader = WebUploader.create({
            auto: true,
            duplicate: true,
            resize: false,
            swf: '/static/js/webuploader/Uploader.swf',
            server: '/admin/attachment/upload/dir/images',
            pick: {
                id: '#picker_' + $input_file_name,
                multiple: $multiple
            },
            fileSingleSizeLimit: $size,
            accept: {
                title: 'Images',
                extensions: $ext,
                mimeTypes: 'image/*'
            }
        });
        
        uploader.on('fileQueued', function(file) {
            
            var $li = $('<li class="col-6 col-sm-3 col-md-2 list-images-item" id="' + file.id + '">' +
                        '  <figure>' +
                        '    <img>' +
                        '    <figcaption>' +
                        '      <a class="btn btn-round btn-square btn-primary btn-link-pic" href="#!"><i class="mdi mdi-eye"></i></a>' +
                        '      <a class="btn btn-round btn-square btn-danger btn-remove-pic" href="#!"><i class="mdi mdi-delete"></i></a>' +
                        '    </figcaption>' +
                        '  </figure>' +
                        '</li>'),
                $img = $li.find('img');
            
            if ($multiple) {
                $file_list.append($li);
            } else {
                $file_list.html($li);
                $input_file.val('');
            }
            uploader.makeThumb(file, function(error, src) {
                if (error) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr('src', src);
            }, thumbnailWidth, thumbnailHeight);
            $('<div class="progress progress-sm"><div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div></div>').appendTo($li);
        });
        uploader.on('uploadProgress', function(file, percentage) {
            var $percent = $('#' + file.id).find('.progress-bar');
            $percent.css('width', percentage * 100 + '%');
        });
        uploader.on('uploadSuccess', function(file, response) {
            var $li = $('#' + file.id);
            if (response.status == 1) {
                if ($multiple) {
                    if ($input_file.val()) {
                        $input_file.val($input_file.val() + ',' + response.id);
                    } else {
                        $input_file.val(response.id);
                    }
                    $li.find('.btn-remove-pic').attr('data-id', response.id);
                } else {
                    $input_file.val(response.id);
                }
            }
            $('<div class="' + response.class + '"></div>').text(response.info).appendTo($li);
            $li.find('a.btn-link-pic').attr('href', response.path);
        });
        uploader.on('uploadError', function(file) {
            var $li = $('#' + file.id);
            $('<div class="bg-danger">上传失败</div>').appendTo($li);
        });
        uploader.on('error', function(type) {
            switch (type) {
            case 'Q_TYPE_DENIED':
                //alert('图片类型不正确，只允许上传后缀名为：' + $ext + '，请重新上传！');
                showNotify('图片类型不正确，只允许上传后缀名为：' + $ext + '，请重新上传！', 'danger');
                break;
            case 'F_EXCEED_SIZE':
                //alert('图片不得超过' + ($size / 1024) + 'kb，请重新上传！');
                showNotify('图片不得超过' + ($size / 1024) + 'kb，请重新上传！', 'danger');
                break;
            }
        });
        uploader.on('uploadComplete', function(file) {
            setTimeout(function() {
                $('#' + file.id).find('.progress').remove();
            }, 500);
        });
        // 删除操作
        $file_list.delegate('.btn-remove-pic', 'click', function() {
            if (confirm("你确认要删除该图片吗?")) { // 可改为对话框插件
                if ($multiple) {
                    var id = $(this).data('id'),
                    ids = $input_file.val().split(',');
                    if (id) {
                        for (var i = 0; i < ids.length; i++) {
                            if (ids[i] == id) {
                                ids.splice(i, 1);
                                break;
                            }
                        }
                        $input_file.val(ids.join(','));
                    }
                } else {
                    $input_file.val('');
                }
                $(this).closest('.list-images-item').remove();
            }
        });
        // 接入图片查看插件
        $(this).magnificPopup({
            delegate: 'a.btn-link-pic',
            type: 'image',
            gallery: {
                enabled: true
            }
        });
    });
    {/if}

    {if condition="isset($useJcrop)"}
    // 图片裁剪
    $('.js-jcrop-interface').each(function () {
        var jcrop_api         = '';
        var $self             = $(this);
        var $jcrop            = $self.find('.js-jcrop');
        var $options          = $jcrop.data('options') || {};
        var $jcrop_cut_btn    = $self.find('.js-jcrop-cut-btn');
        var $jcrop_upload_btn = $self.find('.js-jcrop-upload-btn');
        var $jcrop_file       = $self.find('.js-jcrop-file');
        var $jcrop_cut_info   = $self.find('.js-jcrop-cut-info');
        var $jcrop_preview    = $self.find('.jcrop-preview');
        var $jcrop_input      = $self.find('.js-jcrop-input');
        var $remove_picture   = $self.find('.btn-remove-pic');
        var $thumbnail        = $self.find('.lyear-uploads-pic');
        var $img_link         = $self.find('.btn-link-pic');
        var $modal            = $self.find('.modal-lyear');
        var $pic_height       = '';

        // 设置预览图监听
        $options.onChange    = showPreview;
        $options.onSelect    = showPreview;
        $options.boxWidth    = 568;
        $options.boxHeight   = 381;
        $options.saveWidth   = $options.saveWidth || null;
        $options.saveHeight  = $options.saveHeight || null;
        $options.aspectRatio = $options.aspectRatio || ($options.saveWidth / $options.saveHeight);

        // 点击上传按钮，选择图片
        $jcrop_upload_btn.click(function () {
            $jcrop_file.trigger('click');
        });

        // 加载图片（用于判断图片是否加载完毕）
        function loadImage(url, callback) {
            var img = new Image(); //创建一个Image对象，实现图片的预下载
            img.src = url;

            if(img.complete) { // 如果图片已经存在于浏览器缓存，直接调用回调函数
                callback.call(img);
                return; // 直接返回，不用再处理onload事件
            }
            img.onload = function () { //图片下载完毕时异步调用callback函数。
                callback.call(img);//将回调函数的this替换为Image对象
            };
        }

        // 实时显示预览图
        function showPreview(coords)
        {
            var ratio = coords.w / coords.h; // 选区比例
            var rx,ry;
            var preview_width  = '';
            var preview_height = '';

            if ((100 / ratio) > $pic_height) {
                preview_width  = $pic_height * ratio;
                preview_height = $pic_height;
            } else {
                preview_width  = 100;
                preview_height = 100 / ratio;
            }

            rx = preview_width / coords.w;
            ry = (preview_width / ratio) / coords.h;

            if (jcrop_api) {
                $jcrop_preview.css({
                    width: Math.round(rx * jcrop_api.ui.stage.width) + 'px',
                    height: Math.round(ry * jcrop_api.ui.stage.height) + 'px',
                    marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                    marginTop: '-' + Math.round(ry * coords.y) + 'px'
                }).parent().css({
                    width: preview_width + 'px',
                    height: preview_height + 'px'
                });
            }

            var jcrop_info = [coords.w, coords.h, coords.x, coords.y, $options.saveWidth, $options.saveHeight];
            $jcrop_cut_info.val(jcrop_info.join(','));
        }

        // 选择图片后
        $jcrop_file.change(function () {
            var files = this.files;
            var file;
            if (files && files.length) {
                file = files[0];
                if (/^image\/\w+$/.test(file.type)) {
                    // 创建FormData对象
                    var data = new FormData();
                    // 为FormData对象添加数据
                    data.append('file', file);
                    var jloader = $('body').lyearloading({
                        opacity: 0.2,
                        spinnerSize: 'lg'
                    });
                    // 上传图片
                    $.ajax({
                        url: '/admin/attachment/upload/dir/images/from/jcrop',
                        type: 'POST',
                        cache: false,
                        contentType: false,    //不可缺
                        processData: false,    //不可缺
                        data: data,
                        success: function (res) {
                            if (res.code == 1) {
                                $jcrop.attr('src', res.src).data('id', res.id).show();
                                $jcrop_preview.attr('src', res.src).parent().show();
                                loadImage(res.src, function () {
                                    jloader.destroy();
                                    if (jcrop_api != '') {
                                        jcrop_api.destroy();
                                    }
                                    $jcrop.Jcrop($options, function () {
                                        jcrop_api   = this;
                                        $pic_height = Math.round(jcrop_api.getContainerSize()[1]);
                                        $modal.modal('show');
                                    });
                                });
                            } else {
                                jloader.destroy();
                                showNotify('上传失败，请重新上传', 'warning');
                            }
                        }
                    }).fail(function() {
                        jloader.destroy();
                        showNotify('服务器错误~', 'danger');
                    });
                    $jcrop_file.val('');
                } else {
                    jloader.destroy();
                    showNotify('请选择一张图片', 'warning');
                }
            }
        });

        // 关闭裁剪框
        $modal.on('hidden.bs.modal', function (e) {
            $jcrop_cut_info.val('');
        });

        // 删除图片
        $remove_picture.click(function () {
            if (confirm("你确认要删除该图片吗?")) {
                $(this).closest('.list-images-item').remove();
                $jcrop_input.val('');
            }
        });

        // 裁剪图片
        $jcrop_cut_btn.click(function () {
            var $cut_value = $jcrop_cut_info.val();
            if ($jcrop.attr('src') == '') {
                showNotify('请上传图片', 'danger');
                return false;
            }
            if ($cut_value != '') {
                var $data = {
                    path: $jcrop_preview.attr('src'),
                    cut: $cut_value
                };
                var croploader = $('body').lyearloading({
                    opacity: 0.2,
                    pinnerSize: 'lg'
                });
                $.ajax({
                    url: '/admin/attachment/upload/dir/images/from/jcrop',
                    type: 'POST',
                    dataType: 'json',
                    data: $data
                })
                .done(function(res) {
                    croploader.destroy();
                    if (res.code == '1') {
                        $thumbnail.show().find('img').attr('src', res.thumb || res.src);
                        $jcrop_input.val(res.id);
                        $img_link.attr('href', res.src);
                        $jcrop_cut_info.val('');
                        $modal.modal('hide');
                    } else {
                        croploader.destroy();
                        showNotify(res.msg, 'danger');
                    }
                })
                .fail(function() {
                    croploader.destroy();
                    showNotify('请求失败', 'danger');
                });
            } else {
                croploader.destroy();
                showNotify('请选择要裁剪的大小', 'warning');
            }
        });

        // 查看大图
        $(this).magnificPopup({
            delegate: 'a.btn-link-pic',
            type: 'image',
            gallery: {
                enabled: true
            }
        });
    });
    {/if}

    {if condition="isset($useUeditor)"}
    // ueditor
    $('.js-ueditor').each(function() {
        var ueditor_name = $(this).attr('name');
		var ueditors     = {};
        ueditors[ueditor_name] = UE.getEditor(ueditor_name, {
            initialFrameHeight: 320,
            serverUrl: '/admin/attachment/upload/dir/images/from/ueditor.html'
        });
    });
    {/if}

    {if condition="isset($useWangEditor)"}
    // wangEditor
    var wangeditors = {};
    $('.js-wangeditor').each(function() {
        var wangeditor_name = $(this).attr('name');
        var imgExt  = $(this).data('img-ext') || '';
        var imgSize = $(this).data('img-size') || '';

        // 实例化编辑器
        wangeditors[wangeditor_name] = new wangEditor('#' + wangeditor_name);
        // 上传图片地址
        wangeditors[wangeditor_name].customConfig.uploadImgServer = '/admin/attachment/upload/dir/images/from/wangeditor.html';
        // 允许上传图片后缀
        wangeditors[wangeditor_name].customConfig.uploadImgAccept = imgExt;
        // 限制一次最多上传 1 张图片
        wangeditors[wangeditor_name].customConfig.uploadImgMaxLength = 1;
        if (imgSize > 0) {
            // 允许上传图片大小
            wangeditors[wangeditor_name].customConfig.uploadImgMaxSize = imgSize;
        }
        // 配置文件名
        wangeditors[wangeditor_name].customConfig.uploadFileName = 'file';
        wangeditors[wangeditor_name].customConfig.uploadImgHooks = {
            customInsert: function (insertImg, result, editor) {
                var url = result.url;
                insertImg(url);
            }
        };
        wangeditors[wangeditor_name].create();
    });
    {/if}

    {if condition="isset($useColorpicker)"}
    // 颜色选取
	jQuery('.js-colorpicker').each(function() {
		var $colorpicker = jQuery(this);
		var $colorpickerMode = $colorpicker.data('colorpicker-mode') ? $colorpicker.data('colorpicker-mode') : 'auto';
		$colorpicker.colorpicker({
			'format': $colorpickerMode,
		});
	});
    {/if}
    
    {if condition="isset($useDatepicker)"}
    // 日期选择器
    jQuery("[data-provide = 'datepicker']").each(function() {
        var options = {
            language: 'zh-CN',  // 默认简体中文
            multidateSeparator: ', ' // 默认多个日期用,分隔
        }
  
        options = $.extend( options, getDataOptions( $(this) ));
  
        if ( $(this).prop("tagName") != 'INPUT' ) {
            options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
        }
  
        $(this).datepicker(options);
    });
    {/if}
    
    {if condition="isset($useClockpicker)"}
    // 时间选择器
    jQuery("[data-provide = 'clockpicker']").each(function() {
        $(this).clockpicker({
            donetext: 'Done'
        });
    });
    {/if}
    
    {if condition="isset($useDatetimepicker)"}
    // 时间日期选择器
    jQuery("[data-provide = 'datetimepicker']").each(function() {
        var options = {
            locale: moment.locale(),
        }
  
        options = $.extend( options, getDataOptions( $(this) ));
  
        if ( $(this).prop("tagName") != 'INPUT' ) {
            options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
        }

        $(this).datetimepicker(options);
    });
    {/if}
    
    {if condition="isset($useTagsinput)"}
    // 标签
	$('.js-tags-input').each(function() {
        var $this = $(this);
        $this.tagsInput({
			height: $this.data('height') ? $this.data('height') : '36px',
			width: '100%',
			defaultText: $this.attr("placeholder"),
			removeWithBackspace: true,
			delimiter: [',']
		});
    });
    {/if}

    {if condition="isset($useMagnificPopup) && !isset($useWebuploaderImages) && !isset($useJcrop)"}
    // 图片展示
    jQuery('.js-gallery').each(function() {
		jQuery(this).magnificPopup({
			delegate: 'a.img-link',
			type: 'image',
			gallery: {
				enabled: true
			}
		});
	});
    {/if}

    {if condition="isset($fonticonpicker)"}
    // 图标选择
    var fonticonpickers = {};
    $('.js-fonticonpicker').each(function() {
        var iconpicker_name = $(this).attr('name');
        
        fonticonpickers[iconpicker_name] = $(this).fontIconPicker({
            theme: 'fip-bootstrap'
        });
    
        $.ajax({
            url: '/static/js/fontIconPicker/fontjson/materialdesignicons_v4.json',
            type: 'GET',
            dataType: 'json'
        }).done(function(response) {
 
            var fontello_json_icons = [];
 
            $.each(response.glyphs, function(i, v) {
                fontello_json_icons.push( v.css );
            });
 
            fonticonpickers[iconpicker_name].setIcons(fontello_json_icons);
        }).fail(function() {
            console.error('字体图标配置加载失败');
        });
    });
    {/if}
});
</script>